package com.bs.rocketmq.listen;

import com.alibaba.fastjson.JSON;
import com.bs.rocketmq.vo.UserVo;
import lombok.extern.log4j.Log4j2;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.ConsumeMode;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

/**
 * @author bingshao
 * @date 2022/11/18
 **/
@Log4j2
@Component
@RocketMQMessageListener(
//        nameServer = "192.168.13.101:9876", // 指定其他nameserver
        topic = "async-topic",
//        selectorType = SelectorType.TAG, // 默认就是按TAG 过滤
//        selectorExpression = "tag0||tag1",  // 默认是 *， 接收所有的TAG
        consumeMode = ConsumeMode.CONCURRENTLY, // 默认就是该值。ConsumeMode.ORDERLY和MessageModel.BROADCASTING不能一起设置
        messageModel = MessageModel.CLUSTERING, // 默认就是该值，即集群模式
        consumerGroup = "bs-async-consumer")
public class AsyncConsumerListener implements RocketMQListener<MessageExt> {

    @Override
    public void onMessage(MessageExt messageExt) {
        log.info("异步接收到消息=====>{}", JSON.parseObject(new String(messageExt.getBody()), UserVo.class).toString());
    }
}
